import config from "./config";

export default (url, data={}, method='GET')=> {
   return new Promise((resolve, reject)=>{
       wx.request({
           url: config.host + url,
           data,
           method,
           header:{
               Cookie: wx.getStorageSync("cookies") ? wx.getStorageSync("cookies").find(c=>c.indexOf("MUSIC_U") > -1) : "",
               cookie: "",
           },
           success:(resp)=>{
               if(data.isLogin){
                   if(resp.cookies && resp.cookies.length > 0){
                       wx.setStorage({
                           key:'cookies',
                           data: resp.cookies
                       })
                   }
               }
               resolve(resp.data)
           },
           fail:(e)=> {
               reject(e)
           }
       })
   })
}